package com.gitee.feizns.quickstart.web.domain.ao;

import com.gitee.feizns.dynamic.bean.Convertible;
import lombok.Data;

/**
 * 树查询请求参数
 * @author feizns
 * @since 2023/04/11
 */
@Data
public class TreeAo<T> implements Convertible {

    /**
     * 父编号
     */
    private T parentId;

    /**
     * 递归深度（-1为无限递归.）默认：0
     */
    private int deep = 0;

    /**
     * 可递归的
     * @return boolean
     */
    public boolean isRecursive() {
        return deep > 0;
    }

    /**
     * 子条件
     * @return {@link TreeAo}
     */
    @SuppressWarnings("unchecked")
    public TreeAo<T> subAo(T id) {
        TreeAo<T> ao = this.copyPropertiesTo(TreeAo.class);
        ao.setParentId(id);
        if ( deep > 0 )
            ao.setDeep(deep - 1);
        return ao;
    }

    /**
     * 子条件
     * @return {@link TreeAo}
     */
    @SuppressWarnings("unchecked")
    public TreeAo<T> subAoIdCastAnyType(Object id) {
        return subAo((T) id);
    }

}
